package a51qindian.com.comprehensive.city;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.model.ShopVerifyInfo;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: Li
 * Date: 2017/9/13 0013
 * Description: 店铺审核
 */

public class CityVerifyAdapter extends RecyclerView.Adapter<CityVerifyAdapter.CityVerifyHolder> {



    private LayoutInflater mInflater;
    private Context mContext;
    private OnVerifyListener mOnVerifyListener;
    public CityVerifyAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
        mContext=context;
    }

    private List<ShopVerifyInfo> mShopVerifyInfoList;

    @Override
    public CityVerifyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_city_verify, parent, false);
        final CityVerifyHolder holder=new CityVerifyHolder(view);
        if (mOnVerifyListener != null) {
            holder.mTxtRefuse.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnVerifyListener.onRefuse(holder.getLayoutPosition());
                }
            });
            holder.mTxtPass.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnVerifyListener.onPass(holder.getLayoutPosition());
                }
            });
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(CityVerifyHolder holder, int position) {
        ShopVerifyInfo shopVerifyInfo=mShopVerifyInfoList.get(position);
        Glide.with(mContext).load(shopVerifyInfo.getTitlepic()).into(holder.mImg);
    }

    @Override
    public int getItemCount() {
        return mShopVerifyInfoList == null ? 0 : mShopVerifyInfoList.size();
    }

    public void setShopVerifyInfoList(List<ShopVerifyInfo> shopVerifyInfoList) {
        mShopVerifyInfoList = shopVerifyInfoList;
        notifyDataSetChanged();
    }

    public void setOnVerifyListener(OnVerifyListener onVerifyListener) {
        mOnVerifyListener = onVerifyListener;
    }

    static class CityVerifyHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img)
        ImageView mImg;
        @BindView(R.id.txt_refuse)
        TextView mTxtRefuse;
        @BindView(R.id.txt_pass)
        TextView mTxtPass;
        public CityVerifyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

    public interface OnVerifyListener{
        void onRefuse(int pos);
        void onPass(int pos);
    }


}
